package day16;

import ZUOYE2.E;

import java.nio.charset.StandardCharsets;

public class learn1 implements Runnable {
    public static void main(String[] args) {
        //实例化对象
        learn1 learn1=new learn1();
        learn1 learn2=new learn1();
        learn1 learn3=new learn1();
        learn1 learn4=new learn1();
        //创建线程对象
        Thread thread1=new Thread(learn1,"朱玉");
        Thread thread2=new Thread(learn2,"玉竹");
        Thread thread3=new Thread(learn3,"珠珠");
        Thread thread4=new Thread(learn4,"鱼鱼");
        //启动线程
        thread1.start();
        thread2.start();
        thread3.start();
        thread4.start();
    }
    int money=0;
   int number=1;
   boolean f=true;
    @Override
    public void run() {
        while(f){
            bank();
        }
        /*for(;number<=3;number++){
            money+=100;
            System.out.println(Thread.currentThread().getName()+"第"+number+"次,共存了:"+money);
        }*/
    }
    public synchronized  void bank(){
        try{
            Thread.sleep(100);
            for(;number<=3;number++){
            money+=100;
            System.out.println(Thread.currentThread().getName()+"第"+number+"次,共存了:"+money);
        }
        if(number>3){
            f=false;
            return;
        }
    }catch (Exception e){
            e.printStackTrace();
        }
    }
}








